package com.juyu.miliao.api.controller;

import com.juyu.miliao.api.service.SecretLanguagePlanetService;
import com.juyu.miliao.common.domain.Subject;
import org.apache.xmlbeans.impl.xb.xsdschema.Public;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 密语星球controller
 *
 * @author xuanqicheng
 * @create 2019-03-10:13
 */
@RestController
@RequestMapping("/secretLanguagePlanet")
public class SecretLanguagePlanetController {

    @Autowired
    private SecretLanguagePlanetService secretLanguagePlanetService;

    /**
     *获取展示信息
     * @param token
     * @param number 列表个数，默认5个
     */
    @GetMapping("/list/{number}")
    public List<Map<String, Object>> getList(Authentication token, @PathVariable("number") Integer number) {

        if(number ==null || number ==0){
            number = 5;
        }
        Subject subject = (Subject) token.getPrincipal();

        List<Map<String, Object>> list = secretLanguagePlanetService.getList(subject.getId(), number);

        return list;
    }

    /**
     * 点击头像获取内容
     * @param token
     * @param questionId
     * @return
     */
    @GetMapping("/click/{questionId}")
    public Object getClickQuestion(Authentication token,@PathVariable("questionId") Long questionId){
        Subject subject = (Subject) token.getPrincipal();
        return secretLanguagePlanetService.getClickById(questionId);
    }

    @GetMapping("/{questionId}")
    public Object getQuestionInfo(Authentication token,@PathVariable("questionId") Long questionId){
        Subject subject = (Subject) token.getPrincipal();
        return secretLanguagePlanetService.getQuestionInfoById(questionId,subject.getId());
    }

    @GetMapping("/")
    public Object getLasterQuestionInfo(Authentication token){
        Subject subject = (Subject) token.getPrincipal();
        return secretLanguagePlanetService.getLasterQuestionInfoByUserId(subject.getId());
    }

    @PostMapping("/replace")
    public void getReplace(Authentication token){
        Subject subject = (Subject) token.getPrincipal();

        secretLanguagePlanetService.getReplace(subject.getId());

    }


}
